//
//  DLSettingTC.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/5.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLSettingTC.h"
#import "DLSettingModel.h"


@interface DLSettingTC()

@property (nonatomic, strong) UIImageView *iconImgV;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *subTitleLabel;

@property (nonatomic, strong) UISwitch *switchControl;

@property (nonatomic, strong) UIImageView *rightArrowImgV;
@end

@implementation DLSettingTC



- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self layoutsubControls];
    }
    return self;
}
- (void) layoutsubControls {
    
    UIImageView *iconImgV = [UIImageView new];
    iconImgV.frame = CGRectMake(19, 20 + (74 - 55 - 20) / 2, 55, 55);
    iconImgV.layer.cornerRadius = iconImgV.width / 2;
    iconImgV.clipsToBounds = YES;
    [self.contentView addSubview:iconImgV];
    iconImgV.backgroundColor = [UIColor cyanColor];
    self.iconImgV = iconImgV;
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.frame = CGRectMake(19, 1.5, 140, 55);
    titleLabel.textColor = kDLNormalBlackColor;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.font = kSystemFont(14);
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
//    titleLabel.backgroundColor = [UIColor redColor];
    
    UILabel *subTitleLabel = [UILabel new];
    subTitleLabel.frame = CGRectMake(titleLabel.right, titleLabel.top, kScreenWidth - titleLabel.width - 38 - 12.5, titleLabel.height);
    subTitleLabel.textColor = kColorRGB(200, 200, 200);
    subTitleLabel.textAlignment = NSTextAlignmentRight;
    subTitleLabel.font = kSystemFont(13);
    [self.contentView addSubview:subTitleLabel];
    self.subTitleLabel = subTitleLabel;
//    subTitleLabel.backgroundColor = [UIColor orangeColor];
    
    UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(kScreenWidth - 60 - 19, 11, 0, 0)];
    switchControl.onTintColor = [UIColor orangeColor];
    switchControl.transform = CGAffineTransformMakeScale(0.7, 0.7);
    switchControl.layer.anchorPoint = CGPointMake(0, 0.4);
    [switchControl addTarget:self action:@selector(qqqq:) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview:switchControl];
    self.switchControl = switchControl;
    
    UIImageView *rightArrowImgV = [UIImageView new];
    rightArrowImgV.frame = CGRectMake(subTitleLabel.right, 19, 20, 20);
    rightArrowImgV.image = [UIImage imageNamed:@"right_arrow"];
    [self.contentView addSubview:rightArrowImgV];
    self.rightArrowImgV = rightArrowImgV;
}

- (void) qqqq:(UISwitch *)switchControl {
    
    if (self.switchBlock) {
        self.switchBlock(switchControl);
    }
}

- (void) setSettingModel:(DLSettingModel *)settingModel {
    _settingModel = settingModel;
    if (settingModel.isIconCell == YES) {
        self.iconImgV.hidden = NO;
        self.titleLabel.hidden = NO;
        self.subTitleLabel.hidden = YES;
        self.switchControl.hidden = YES;
        self.rightArrowImgV.hidden = YES;
        [self.titleLabel resetX:self.iconImgV.right + 19];
        [self.titleLabel resetY:self.iconImgV.top];
        self.titleLabel.textColor = [UIColor whiteColor];
        self.titleLabel.text = kuserManager.userInfoModel.mobile;
    } else {
        self.iconImgV.hidden = YES;
        self.titleLabel.hidden = NO;
        self.titleLabel.textColor = kDLNormalBlackColor;
        if (settingModel.isDifferentCell == YES) {
            self.switchControl.hidden = NO;
            self.subTitleLabel.hidden = YES;
            self.rightArrowImgV.hidden = YES;
        } else {
            self.switchControl.hidden = YES;
            self.subTitleLabel.hidden = NO;
            self.rightArrowImgV.hidden = NO;
        }
    }
    
    if (settingModel.isIconCell == NO) {
        
        self.titleLabel.text = settingModel.leftTitle;
        self.subTitleLabel.text = settingModel.subTitle;
    }
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
